namespace RetailAnalytic.Tools.MGrouping
{
    using Infragistics.Win.UltraWinTree;
    using System;
    using System.Collections;
    using RetailAnalytic.Core;

    public class NodeUtils
    {
        public static void blockBound(TreeNodesCollection leftColl, UltraTree right)
        {
            ArrayList list1 = new ArrayList();
            NodeUtils.filterItems(leftColl, list1);
            foreach (UltraTreeNode node1 in list1)
            {
                NodeData data1 = (NodeData) node1.DataKey;
                UltraTreeNode node2 = right.GetNodeByKey(node1.Key);
                NodeData data2 = (NodeData) node2.DataKey;
                data2.brotherData = data1;
                data2.IsBlocked = true;
                data1.brotherData = data2;
            }
        }

        public static void DeleteNode(UltraTreeNode node)
        {
            
            for (int num1 = node.Nodes.Count - 1; num1 >= 0; num1--)
            {
                NodeUtils.DeleteNode(node.Nodes[num1]);
            }
            NodeData data1 = (NodeData) node.DataKey;
            NodeData data2 = data1.brotherData;
            if (data2 != null)
            {
                data2.brotherData = null;
                if (data1.IsItem)
                {
                    data2.IsBlocked = false;
                }
            }
            node.Remove();
            
        }

        public static void filterItems(TreeNodesCollection source, ArrayList accum)
        {
            
            foreach (UltraTreeNode node1 in source)
            {
                NodeData data1 = (NodeData) node1.DataKey;
                if (data1.IsItem)
                {
                    accum.Add(node1);
                }
                else if (node1.Nodes.Count > 0)
                {
                    NodeUtils.filterItems(node1.Nodes, accum);
                }
            }
            
        }

    }
}

